#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
const int N = 55;
int a[N];
map<int, int>mp;
int n, m, k, h;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m >> k >> h;
		mp.clear();
	    //mp[0] = 1;
		int sum = 0;
		vector<int>res;
		for (int i = 1; i <= m; i++) {
			res.push_back(i * k);
		}
		for (auto x : res) {
			for (auto y : res) {
				if (!mp[abs(y - x)]) {
					mp[abs(y - x)] = 1;
				}
			}
		}
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (mp[abs(a[i] - h)] && a[i] != h)ans++;
		}
		cout << ans << endl;
	}
	return 0;
}